<template>
	<view class="margin-top bg-white padding-lr">
		<u-form :model="info" ref="form" label-width="auto">
			<u-form-item label="规则名称" prop="ruleName" required><u-input v-model="info.ruleName" :border="true" /></u-form-item>
			<u-form-item label="规则内容" prop="ruleContent" required><u-input type="textarea" v-model="info.ruleContent" height="800" :maxlength="-1" :border="true" /></u-form-item>
			<view class="padding-tb"><u-button type="primary" @click="save">保存</u-button></view>
		</u-form>
	</view>
</template>

<script>
export default {
	onLoad: function(option) {
		if (option.info) {
			this.info = JSON.parse(decodeURIComponent(option.info));
		}
	},
	onReady: function() {
		this.$refs.form.setRules(this.rules);
	},
	data() {
		return {
			show: false, // 显示选项
			info: {
				id: '',
				ruleName: '',
				ruleContent: ''
			},
			rules: {
				ruleName: [{ required: true, message: '必填', trigger: ['change', 'blur'] }],
				ruleContent: [{ required: true, message: '必填', trigger: ['change', 'blur'] }]
			}
		};
	},
	methods: {
		// 保存用户
		save: function() {
			this.$refs['form'].validate(valid => {
				if (valid) {
					this.$request.post(
						'/admin/sys/drools/drl/save',
						this.info,
						res => {
							this.$utils.showModal('保存成功！', () => {
								uni.navigateBack({
									delta: 1
								});
							});
						},
						false,
						true,
						true
					);
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped></style>
